package com.itheima.exception;

import java.util.Scanner;

/**
 * @Author 王加鑫
 * @Date 2021/5/12 17:03
 * @Version 1.0
 */
public class ExceptionTest2 {
    public static void main(String[] args) {
        Student stu = new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名:");
        String name = sc.next();
        stu.setName(name);
        while (true){
            System.out.println("请输入年龄:");
            String age = sc.next();
            try {
                stu.setAge(Integer.parseInt(age));
                break;
            } catch (NumberFormatException e) {
                System.out.println("您输入的数据有误");
                continue;
            }catch (RuntimeException e){
                System.out.println("请输入一个符合范围的年龄");
                continue;
            }
        }
        System.out.println(stu);
    }
}
